
#ifndef _PID_H
#define _PID_H

#include "main.h"

typedef struct _pid_struct_t
{
  float kp;
  float ki;
  float kd;
  float i_max;
  float out_max;

  float ref;      // target value
  float fdb;      // feedback value
  float err[2];   // error and last error

  float p_out;
  float i_out;
  float d_out;
  float output;
}pid_struct_t;
typedef struct pid_count
{
	float kp;
	float ki;
	float kd;
}pid_count;
typedef struct
{
	uint16_t encoder;
	uint16_t last_encoder;
	uint16_t encoder_offset;
	uint16_t angle_offset;
	uint16_t round_cnt;
	uint16_t total_encoder;
	uint16_t angle ;
	uint16_t encoder_is_init;
}motor_angle;
void update_angle(motor_angle* _angle,uint16_t angle_fb);
void pid_init(pid_struct_t *pid,
              float kp,
              float ki,
              float kd,
              float i_max,
              float out_max);

float  pid_calc(pid_struct_t *pid, float ref, float fdb);
#endif
